/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.demo.domain.das;

import cn.hallele.ms.demo.domain.domain.PostDomain;
import cn.hallele.ms.demo.model.cache.DemoCache;
import cn.hallele.ms.demo.model.entity.DemoEntity;
import cn.hallele.ms.infrastructure.core.convertor.das.ModelDas;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * TypicodeDomian - TypicodeEntity转换器
 *
 * @author anle5
 * @since 2024/9/15 15:57
 */
@Slf4j
@Component
public class PostDEDas extends ModelDas<DemoCache, PostDomain, DemoEntity> {
    public PostDEDas(DemoCache option) {
        super(option);
    }

    public PostDomain findOne(int id) {
        return revert(this.option.findOneById(id));
    }

    /**
     * 将T转成E
     *
     * @param postDomain 被转换者
     * @return E 转换后者
     */
    @Override
    protected DemoEntity convert(PostDomain postDomain) {
        return DemoEntity.builder()
                .id(postDomain.getId())
                .text(postDomain.getText())
                .build();
    }

    /**
     * 将E回转陈T
     *
     * @param demoEntity 被回转换者
     * @return E 回转换后者
     */
    @Override
    protected PostDomain revert(DemoEntity demoEntity) {
        return PostDomain.builder()
                .id(demoEntity.getId())
                .text(demoEntity.getText())
                .build();
    }
}
